// 1.字面量类型的基本使用
const name: "why" = "why"
let age: 18 = 18

// 2.将多个字面量类型联合起来
type Direction = "left" | "right" | "up" | "down"
const d1: Direction = "left"

// 例子:封装请求方法
type MethodType = "get" | "post"
function request(url: string, method: MethodType) {
}
request("http://www.baidu.com", "get")

// TS细节
const info = {
  url: "xxx",
  method: "post"
}
// request(info.url, info.method) // 错误的做法
// 解决方案一
request(info.url, info.method as "post")
// 解决方案二 直接让info对象类型是个字面量类型
const info1: { url: string, method: "post" } = {
  url: "xxx",
  method: "post"
}
request(info1.url, info1.method)

// as const 使整个info变为字面量
const info2 = {
  url: "xxx",
  method: "post"
} as const
request(info2.url, info2.method)

export { }